package br.poli.ecomp.tcc.stimultimidia.view
{
	import br.poli.ecomp.tcc.stimultimidia.notification.TelaNotification;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class AppMediator extends Mediator implements IMediator
	{
		public static const NAME:String = 'APP';
		
		public function AppMediator( viewComponent:Object=null)
		{
			
			super(NAME, viewComponent);
		}
		
		
		public function get sti():STIAS3{
			return viewComponent as STIAS3;
		}
		
		
		override public function listNotificationInterests():Array
		{
			return [
				TelaNotification.ABRIR_TELA_LOGIN,
				TelaNotification.ABRIR_TELA_CADASTRO,
				TelaNotification.ABRIR_TELA_MAIN
				
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			
			switch ( notification.getName() )
			{
				
				case TelaNotification.ABRIR_TELA_LOGIN:
					sti.addChild( sti.login );
					break;
				
				case TelaNotification.ABRIR_TELA_CADASTRO:
					if(sti.contains( sti.login ) ) sti.removeChild( sti.login );
					sti.addChild( sti.cadastro );
					break;
				
				case TelaNotification.ABRIR_TELA_MAIN:
					if(sti.contains( sti.login ) ) sti.removeChild( sti.login );
					if(sti.contains( sti.cadastro ) ) sti.removeChild( sti.cadastro );
					sti.addChild( sti.main );
					break;
				
				default : break;
			}
			
		}
		
	}
}